package com.xinyi.shicihui.controller;

import com.xinyi.shicihui.pojo.entity.Shiren;
import com.xinyi.shicihui.pojo.result.Result;
import com.xinyi.shicihui.pojo.vo.ShiciDetailVo;
import com.xinyi.shicihui.pojo.vo.ShirenDetailVo;
import com.xinyi.shicihui.service.ShirenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author xinyi
 * @desc 诗人信息管理接口
 * @date 2022/1/25
 */
@RestController
@RequestMapping("/api/v1/shiren")
public class ShirenController {
    @Autowired
    private ShirenService shirenService;

    @GetMapping("/page")
    public Result<Page<Shiren>> page(@RequestParam(value = "page") @NotNull(message = "请输入当前页") @Min(value = 1, message = "请输入有效页数") Integer page,
                                     @RequestParam(value = "dynastyId", defaultValue = "-1") String dynastyId,
                                     @RequestParam(value = "size", defaultValue = "10") @Max(value = 50, message = "限制每页最大查询50条记录") Integer size) {

        return Result.success(shirenService.pageQuery(page, size, dynastyId));
    }

    @GetMapping("/detail")
    public Result<ShirenDetailVo> detail(@RequestParam("id") @NotNull(message = "请输入诗词ID") String id) {

        return Result.success(shirenService.detail(id));
    }
}
